import Resource from "../models/resourceModel";

export default class ResourcesController {
  static async apiPostResource(req, res, next) {
    try {
      const { coursename, creator } = req.body;
      const newResource = new Resource({
        coursename,
        creator,
      });
      await newResource.save();
      res.status(200).json({ data: newResource});
    } catch (e) {
      res.status(500).json({ error: e.message });
    }
  }

  static async apiGetResource(req, res, next) {
    try {
        // TODO add support for different type of get resource query
        // like by id, by name ...
      const resource = await Resource.find({});
      res.status(200).json(resource);
    } catch (e) {
      res.status(500).json({ error: e.message });
    }
  }

}
